# -*-coding:utf-8
# ProjectName: property-ui-auto-test
# FileName: personnel_group.py
# @Time :2022/9/27 15:17
# @Author :
# @Description:权限配置-员工管理

from time import sleep

from page.login_page import LoginPage


class ManagerManagementGroup(LoginPage):
    def personnel_management_setup(self):
        # 展开菜单栏
        self.click('//*[@id="app"]/section/section/aside/div/img')
        sleep(1)
        # 展开菜单-权限配置
        self.click('//*[@id="app"]/section/section/aside/div/div/ul/li[7]/div')
        sleep(1)
        # 展开菜单-权限配置-员工管理
        self.click('//*[@id="app"]/section/section/aside/div/div/ul/li[7]/ul/li[2]/ul/li')

    # 新增人员
    def manager_management_addUser(self, mobilephone='18200000000', passwd='test1234', name='tester',
                                   email='123@qq.com',optPwd=123123):
        self.personnel_management_setup()
        # 点击新增人员按钮
        self.click('//*[@id="app"]/section/section/main/section/section/section/header/div/div/form/div[4]/div/button')
        # 输入电话号
        self.send_keys(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[1]/div/div/input',
            mobilephone)
        # 选择角色类型
        self.click(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[2]/div/div/div/input')
        sleep(1)
        self.click('/html/body/div[3]/div[1]/div[1]/ul/li[1]')
        # 选择角色
        self.click(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[3]/div/div/div/input')
        sleep(0.5)
        self.second_location('/html/body/div[4]/div[1]/div[1]/ul', 'li')
        # 选择集团
        self.click('//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[4]/div/div/div[1]/input')
        sleep(1)
        self.driver.find_elements_by_class_name('el-cascader-menu__wrap')[1].find_elements_by_class_name('el-radio__inner')[0].click()
        self.click('//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[1]/span')
        sleep(0.2)
        # 输入密码
        self.send_keys(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[5]/div/div/input',
            passwd)
        # 输入确认密码
        self.send_keys(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[6]/div/div/input',
            passwd)
        # 输入姓名
        self.send_keys(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[7]/div/div/input',
            name)
        # 输入邮箱地址
        self.send_keys(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[8]/div/div/input',
            email)
        # 提交
        self.click('//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[3]/div/button[2]')
        # 输入操作密码
        self.send_keys('/html/body/div[5]/div/div[2]/div[2]/div[1]/input',optPwd)
        # 确定
        self.click('/html/body/div[5]/div/div[3]/button[2]')

    # 删除人员
    def manager_management_del(self, optpwd='123123'):
        """

        :param optpwd: 操作密码
        :return:
        """
        self.personnel_management_setup()
        self.click(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[1]/div[3]/table/tbody/tr[1]/td[9]/div')
        # 输入操作密码
        self.send_keys('/html/body/div[2]/div/div[2]/div[2]/div[1]/input', optpwd)
        self.click('/html/body/div[2]/div/div[3]/button[2]')

    # 修改人员密码
    def manager_management_editPw(self, passwd='test1234', optpwd='123123'):
        """

        :param passwd: 密码
        :param optpwd: 操作密码
        :return:
        """
        self.personnel_management_setup()
        sleep(0.5)
        # 点击密码修改按钮
        self.click(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[1]/div[3]/table/tbody/tr[1]/td[9]/div/img[2]')
        # 密码输入框
        self.send_keys(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[1]/div/div/input',
            passwd)
        # 确认密码输入框
        self.send_keys(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[2]/div/div/input',
            passwd)
        # 提交按钮
        self.click('//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[3]/div/button[2]')
        # 输入操作密码
        self.send_keys('/html/body/div[2]/div/div[2]/div[2]/div[1]/input', optpwd)
        self.click('/html/body/div[2]/div/div[3]/button[2]')

    # 编辑人员
    def manager_management_editInfo(self, name='tester1', email='1234@qq.com', optpwd='123123'):
        self.personnel_management_setup()
        sleep(0.5)
        # 点击编辑按钮
        self.click(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[1]/div[3]/table/tbody/tr[1]/td[9]/div/img[1]')
        # 输入姓名
        self.send_keys(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[5]/div/div/input',
            name)
        # 输入邮箱
        self.send_keys(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[6]/div/div/input',
            email)
        # 点击提交
        self.click('//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[3]/div/button[2]')
        # 输入操作密码
        self.send_keys('/html/body/div[5]/div/div[2]/div[2]/div[1]/input', optpwd)
        self.click('/html/body/div[5]/div/div[3]/button[2]')


if __name__ == '__main__':
    mm = ManagerManagementGroup()
    mm.login()
    mm.manager_management_addUser()
    sleep(5)
    mm.quit()
